#ifndef HTABLE_H
#define HTABLE_H

/**
 * @file htable.h
 * @brief hash tables
 */

#include <stddef.h>
#include <stdio.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef enum ht_action_e
{
    HT_CONTINUE = 1 << 0,
    HT_BREAK    = 1 << 1,
    HT_REMOVE   = 1 << 2
}ht_action_e;

typedef struct htable htable_t;
typedef unsigned int (*ht_hashfunc_t)(const void *key, int *klen);
typedef ht_action_e (* ht_iterfunc_t)(void* ctx, const void* key, int ksize, void* val);

htable_t* htable_create(size_t nel);
void htable_free(htable_t* me);
void htable_clear(htable_t* me);

int htable_set(htable_t* me, const void* key, int ksize, void* val);
int htable_add(htable_t* me, const void* key, int ksize, void* val);
void* htable_get(htable_t* me, const void* key, int ksize);
void* htable_rm(htable_t* me, const void* key, int ksize);

size_t htable_count(htable_t* me);

void htable_set_hash(htable_t* me, ht_hashfunc_t func);
void htable_set_plex(htable_t* me, unsigned int nmemb);
void htable_enable_expand(htable_t* me, int enable);

/* iterate */
void htable_iterate(htable_t* me, ht_iterfunc_t iter, void* ctx);

void htable_dump(htable_t* me, FILE* to);

#ifdef __cplusplus
}
#endif

#endif /* HTABLE_H */

